var nodemailer = require('nodemailer');
module.exports = {
  sendEmail: function (options) {
    var subject = options.subject || '';
    var text = options.text || '';
    return new Promise(function (resolve, reject) {
      var transporter = nodemailer.createTransport({
        host: 'smtp.qq.com',
        port: 465,
        secure: true,
        auth: {
          user: '1021969874@qq.com',
          pass: 'kypxgaebvbqlbcfa'
        }
      });
      var toList = ['1021969874@qq.com'];
      var mailOptions = {
        from: '1021969874@qq.com',
        subject: subject,
        text: text
      };
      var mailOptionsWithTo = Object.assign({}, mailOptions, {
        to: toList[0]
      });
      transporter.sendMail(mailOptionsWithTo, function (error, info) {
        if (error) {
          console.log("[email|L48|C -> sendEmail]", error);
          reject(error);
          return;
        }
        console.log("[email|L52|C -> sendEmail]", '邮件已发送: %s', info.messageId);
        console.log("[email|L53|C -> sendEmail]", mailOptions.text);
        resolve(info);
      });
    });
  }
};